/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.form.client.form.impl;

import com.genia.toolbox.web.gwt.form.client.form.InlineFormSimpleItem;
import com.genia.toolbox.web.gwt.form.client.visitor.FormVisitor;

/**
 * implementation of {@link InlineFormSimpleItem}.
 */
public class InlineFormSimpleItemImpl
    extends AbstractInlineFormItem
    implements InlineFormSimpleItem
{

  /**
   * whether this item can take the null value.
   */
  private Boolean nullable = Boolean.FALSE;



  /**
   * make class visitable by visitor.
   * 
   * @param visitor
   *          the visitor implementation
   * @see com.genia.toolbox.web.gwt.form.client.form.Form#accept(com.genia.toolbox.web.gwt.form.client.visitor.FormVisitor)
   */
  public void accept(FormVisitor visitor)
  {
    visitor.visitInlineFormSimpleItem(this);
  }



  /**
   * Indicates whether some other object is "equal to" this one.
   * 
   * @param obj
   *          the reference object with which to compare.
   * @return <code>true</code> if this object is the same as the obj argument;
   *         <code>false</code> otherwise.
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(final Object obj)
  {
    if (obj == this) {
      return true;
    }
    if (!super.equals(obj)) {
      return false;
    }
    return (obj instanceof InlineFormSimpleItem);
  }



  /**
   * returns the maximum number of sub forms to display. If the value is
   * <code>null</code>, there is not limit to the number of sub forms.
   * 
   * @return the maximum number of sub forms to display. If the value is
   *         <code>null</code>, there is not limit to the number of sub forms
   */
  public Integer getMaximumNumberOfSubForm()
  {
    return new Integer(1);
  }



  /**
   * returns the minimum number of sub forms to display.
   * 
   * @return the minimum number of sub forms to display
   */
  public int getMinimumNumberOfSubForm()
  {
    return nullable.booleanValue() ? 0 : 1;
  }



  /**
   * getter for the nullable property.
   * 
   * @return the nullable
   */
  public Boolean getNullable()
  {
    return nullable;
  }



  /**
   * setter for the nullable property.
   * 
   * @param nullable
   *          the nullable to set
   */
  public void setNullable(Boolean nullable)
  {
    this.nullable = nullable == null ? Boolean.FALSE : nullable;
  }
}
